package com.ayf.payment.game.api.service.impl;

import com.ayf.payment.game.api.entity.TemplateCustomize;
import com.ayf.payment.game.api.exception.ParameterException;
import com.ayf.payment.game.api.mapper.TemplateCustomizeMapper;
import com.ayf.payment.game.api.service.TemplateCustomizeService;
import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TemplateCustomizeServiceImpl implements TemplateCustomizeService{

    @Resource
    private TemplateCustomizeMapper templateCustomizeMapper;

    @Override
    public void insertCustomizes(List<TemplateCustomize> customizes) {
        templateCustomizeMapper.insertCustomizes(customizes);
    }

    @Override
    public List<TemplateCustomize> selectAllByTemplateId(String id) {

        return templateCustomizeMapper.selectByTemplateId(id);
    }

    private TemplateCustomize checkParameter(String templateId) {
        if (StringUtils.isBlank(templateId)) {
            throw new ParameterException("模板id不能为空");
        }
        TemplateCustomize customize = new TemplateCustomize();
        customize.setTemplateId(templateId);
        return customize;
    }

    @Override
    public boolean delCustomizeByTemId(String id) {
        TemplateCustomize temp = checkParameter(id);
        return templateCustomizeMapper.delete(temp) > 0;
    }
}
